package com.sakura.oj.sandbox;

import cn.hutool.core.io.FileUtil;
import com.sakura.oj.sandbox.constants.CommonConstant;
import com.sakura.oj.sandbox.model.ExecuteCodeRequest;
import com.sakura.oj.sandbox.model.ExecuteCodeResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication
public class SandboxApplication implements ApplicationRunner {


    public static void main(String[] args) {
        SpringApplication.run(SandboxApplication.class, args);
    }

    // 1) 拿到用户的工作目录
    private static final String GLOBAL_CODE_PATH = CommonConstant.GLOBAL_CODE_DIR;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("代码工作目录启动");
        // 2） 没有就创建工作目录
        if (!FileUtil.exist(GLOBAL_CODE_PATH)) {
            // 创建
            FileUtil.mkdir(GLOBAL_CODE_PATH);
            log.info("代码工作目录创建成功");
        }
        log.info("代码工作目录启动成功");
    }
}
